* Summary analysis of gun legislation and politics
*
* Which party and legislatures introduce the most bills
* and pass the most tightening/loosening laws?


clear all
set more off

include "bill-analysis/bill_setup.do"  // load data and setup variables
run _reg_labels.do             // simplify variable labels for output

loc lhs `billdv' `lawdv' laws_tighten laws_loosen

// relationship between politics and gun legislation {{{
eststo clear
loc m = 1
foreach dv of varlist `lhs' {
    // no controls
    poisson `dv' ibn.legis_control `rng', vce(robust)
    qui estadd local yfix = "No"
    qui estadd local sfix = "No"
    eststo m`m', title("`dv' No Control")
    loc m = `m' + 1

    // with controls
    poisson `dv' ibn.legis_control `gov' `demo' `rng', vce(robust)
    qui estadd local yfix = "No"
    qui estadd local sfix = "No"
    eststo m`m', title("`dv' Controls")
    loc m = `m' + 1

    // with state fixed effect
    xtpoisson `dv' ibn.legis_control `gov' `demo' `rng', fe vce(robust)
    qui estadd local yfix = "No"
    qui estadd local sfix = "Yes"
    eststo m`m', title("`dv' FE")
    loc m = `m' + 1

    // with year and state fixed effects
    xtpoisson `dv' ibn.legis_control `gov' `demo' i.year `rng', fe vce(robust)
    qui estadd local yfix = "Yes"
    qui estadd local sfix = "Yes"
    eststo m`m', title("`dv' FE")
    loc m = `m' + 1
}  // }}}

loc wopt "ext(rtf) drop(*.year)"
writemodel m1 m2 m3 m4 m5 m6 m7 m8 using "`out'/parties_laws", `wopt'
writemodel m9 m10 m11 m12 m13 m14 m15 m16  using "`out'/parties_dirs", `wopt'

// summary statistics  {{{
loc serr ""
loc mu ""
foreach v of varlist `lhs' {
    loc serr "`serr' se`v'=`v'"
    loc mu "`mu' mu`v'=`v'"
}
collapse (mean) `mu' (semean) `serr' `rng', by(legis_control) fast
reshape long mu se, i(legis_control) j(dv) string
// }}}

// save statistics for graph_party_sum.r
saveold "`out'/party_summary.dta", replace

// create a table suitable for paper {{{
reshape wide @mu @se , i(legis_control) j(dv) string
reshape long `billdv' `lawdv' laws_loosen laws_tighten /*
    */ , i(legis_control) j(stat) string

format %4.2f `billdv' `lawdv' laws_*
outsheet using "`out'/party_summary.csv", comma replace
// }}}

exit
// vim: foldmethod=marker
